package com.woniuxy.stage3demo.controller.otherPzc;

import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.ResultMsg;
import com.woniuxy.stage3demo.bean.otherPzc.ApplyForDataConfigBean;
import com.woniuxy.stage3demo.bean.otherPzc.PhoneCheckBean;
import com.woniuxy.stage3demo.bean.otherPzc.QainforBean;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.pageHelper.TableResult;
import com.woniuxy.stage3demo.service.otherPzc.IApplyForDataConfigService;
import com.woniuxy.stage3demo.service.otherPzc.IPhoneCheckService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/phonecheck")
@RestController
public class PhoneCheckController {

    @Resource
    private IPhoneCheckService phoneCheckServiceImpl;

    @RequestMapping(value = "/page",produces = {"application/json;charset=utf-8"})
    public TableResult<PhoneCheckBean> findAllByParams(PageRequest request, PhoneCheckBean phoneCheckBean){
        System.out.println(phoneCheckBean.getType());
        PageInfo<PhoneCheckBean> pageInfo = phoneCheckServiceImpl.findAllByParams(request, phoneCheckBean);
        return new TableResult<>(pageInfo.getTotal(),pageInfo.getList());
    }

    @RequestMapping(value = "/category",produces = {"application/json;charset=utf-8"})
    public ResultMsg<List<String>> findAllByParams(){
        ResultMsg<List<String>> res = new ResultMsg<>(200,"操作成功",null);
        List<String> allCategory = phoneCheckServiceImpl.findAllCategory();
        res.setData(allCategory);
        return res;
    }
    @DeleteMapping(value = "/{id}",produces = {"application/json;charset=utf-8"})
    public ResultMsg qaInforDel(@PathVariable("id") Long id){
        ResultMsg res = new ResultMsg(200,"操作成功",null);
        if(id != null) {
            phoneCheckServiceImpl.deletePhoneCheck(id.intValue());
            return res;
        }else{
            res.setCode(10000);
            res.setMsg("更改失败");
            return res;
        }
    }

    @PutMapping(value = "/status/{id}/{status}",produces = {"application/json;charset=utf-8"})
    public ResultMsg statusUpdate(@PathVariable("id") Long id,@PathVariable("status") Integer status){
        ResultMsg res = new ResultMsg(200,"操作成功",null);
        if(id != null && status != null) {
            PhoneCheckBean phoneCheckBean = new PhoneCheckBean();
            phoneCheckBean.setId(id);
            phoneCheckBean.setStatus(status);
            phoneCheckServiceImpl.updatePhoneCheck(phoneCheckBean);
            return res;
        }else{
            res.setCode(10000);
            res.setMsg("更改失败");
            return res;
        }
    }

    @PostMapping(value = "/more",produces = {"application/json;charset=utf-8"})
    public ResultMsg save(@RequestBody PhoneCheckBean phoneCheckBean){
        System.out.println(phoneCheckBean);
        ResultMsg res = new ResultMsg(200,"操作成功",null);
        if(phoneCheckServiceImpl.savePhoneCheck(phoneCheckBean) == 1){
            return res;
        }else{
            res.setCode(10000);
            res.setMsg("修改失败");
            return res;
        }
    }

}
